home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-11-17 | 6.2 KB | 248 lines | [TEXT/KAHL] |
- /******************************************************************************
- CConfigDirector.c
-
-
- SUPERCLASS = CDLOGDirector
-
- Copyright © 1991 Symantec Corporation. All rights reserved.
-
-
- ******************************************************************************/
-
- #include "CConfigDirector.h"
- #include <CScrollPane.h>
- #include <CDialogText.h>
- #include <CDialog.h>
- #include <CPaneBorder.h>
- #include <CApplication.h>
- #include <CTextEnvirons.h>
- #include <CButton.h>
- #include <CCheckBox.h>
- #include <CRadioControl.h>
- #include <CDialogText.h>
- #include <CPopupMenu.h>
- #include <CPopupPane.h>
- #include <CBartender.h>
-
- extern CBartender *gBartender;
-
- char gOptions[500];
- extern short prefsRefNum;
-
- static Boolean ByKind( CView *scrollPane, void* targetID)
- {
- return member(scrollPane, CScrollPane);
- }
-
- static Boolean ByKind_set_text( CView *pane, void* targetID)
- {
- if (member(pane, CDialogText))
- {
- short id = ((CDialogText *)pane)->GetID();
- Handle aResource = GetResource('PREF',id);
- ((CDialogText *)pane)->SetTextHandle(aResource);
- }
- }
-
- static Boolean ByKind_get_text( CView *pane, void* targetID)
- {
- if (member(pane, CDialogText))
- {
- short id = ((CDialogText *)pane)->GetID();
- Handle aResource = GetResource('PREF',id);
- if (!aResource)
- {
- aResource = NewHandle(0);
- AddResource(aResource,'PREF',id,"\p");
- }
- else
- {
- SetHandleSize(aResource, 0);
- }
- HandAndHand(((CDialogText *)pane)->GetTextHandle(), aResource);
- ChangedResource(aResource);
- WriteResource(aResource);
- }
- }
-
- static Boolean ByCommand( CView *item, void* targetID)
- {
- long command = (long)targetID;
-
- if (member(item, CButton) && (command == ((CButton *)item)->GetClickCmd()))
- {
- return ((CButton *)item)->GetValue() || !member(item, CRadioControl);
- }
- else if (member(item, CPopupPane))
- {
- CPopupMenu *aMenu = ((CPopupPane *)item)->GetMenu();
- short selectedItem, mID;
- MenuHandle mHandle;
-
- gBartender->FindMenuItem( command, &mID, &mHandle, &selectedItem);
-
- return (selectedItem != 0);
- }
- else
- return false;
- }
-
- void CConfigDirector::IConfigDirector( short Aboutid, CDirectorOwner *aSupervisor)
- {
- long theCommand;
- CScrollPane *scrollPane;
- Handle Data = GetResource( 'TEXT', Aboutid);
- Str255 name;
- ResType rType;
- FailNILRes(Data);
- GetResInfo(Data,&Aboutid,&rType,name);
-
- CDLOGDirector::IDLOGDirector( Aboutid, aSupervisor);
-
- itsData = Data;
- itsWindow->SetTitle(name);
- scrollPane = (CScrollPane *)itsWindow->MatchView( ByKind, 0);
-
- if (scrollPane)
- {
- StScrpHandle styleHandle = (StScrpHandle) GetResource( 'styl', Aboutid);
- CPaneBorder *listBorder;
- Rect margin;
- Cell aCell;
-
- itsMainPane = new(CStyleText);
- itsGopher = itsMainPane;
-
- itsMainPane->IStyleText(scrollPane, this,
- 1, 1, 0, 0, sizELASTIC, sizELASTIC, 1000);
- itsMainPane->Specify( kNotEditable, kNotSelectable, kNotStylable);
- itsMainPane->FitToEnclosure(TRUE, TRUE);
- itsMainPane->Offset( 2, 2, FALSE);
- SetRect(&margin, 0, 0, -2, -2);
- itsMainPane->ChangeSize( &margin, FALSE);
-
- if (Data) itsMainPane->SetTextHandle(Data);
-
- // Install the styles
-
- if (styleHandle) itsMainPane->SetStyleScrap( 0, MAXINT, styleHandle, TRUE);
-
- scrollPane->InstallPanorama(itsMainPane);
- }
-
- UseResFile(prefsRefNum);
- itsWindow->MatchView( ByKind_set_text, 0);
-
- for ( theCommand = 20000 ; theCommand < 21000; theCommand += 2)
- {
- int deflt = gOptions[(theCommand-20000)>>1];
- /* set check box / radio button state */
-
- if (deflt < 2)
- {
- CButton *hit = (CButton *)itsWindow->MatchView( ByCommand, (void *)theCommand);
- if (hit && member(hit, CCheckBox))
- {
- ((CCheckBox *)hit)->SetValue(deflt);
- }
- else if (hit && member(hit, CPopupPane))
- {
- CPopupMenu *aMenu = ((CPopupPane *)hit)->GetMenu();
- short selectedItem, mID;
- MenuHandle mHandle;
-
- gBartender->FindMenuItem( theCommand, &mID, &mHandle, &selectedItem);
-
- aMenu->SelectItem(selectedItem, deflt?pmForceOn:pmForceOff);
- }
- }
- else
- {
- CRadioControl *hit = (CRadioControl *)itsWindow->FindViewByID(deflt);
- if (hit && member(hit, CRadioControl))
- hit->SetValue(BUTTON_ON);
- }
- }
- } /* CConfigDirector::IConfigDirector */
-
- void CConfigDirector::Dispose( void)
- {
- UseResFile(prefsRefNum);
- if (!ResError())
- {
- Handle aResource = GetResource('PREF',20000);
- if (!aResource)
- {
- aResource = NewHandle(0);
- AddResource(aResource,'PREF',20000,"\pgcc switches");
- }
- else
- {
- SetHandleSize(aResource, 0);
- }
- PtrAndHand(&gOptions, aResource, sizeof (gOptions));
- ChangedResource(aResource);
- WriteResource(aResource);
- itsWindow->MatchView( ByKind_get_text, 0);
- }
- itsMainPane = 0;
- inherited::Dispose();
- }
-
- void CConfigDirector::DoCommand( long theCommand)
- {
- Handle Data = NULL;
- StScrpHandle styleHandle = NULL;
- CButton *hit = NULL;
-
- if (( theCommand >= 20000 ) && ( theCommand < 21000)) /* check boxes / radio buttons */
- {
- /* save check box / radio button state */
- int idx = (theCommand-20000)>>1;
- hit = (CButton *)itsWindow->MatchView( ByCommand, (void *)theCommand);
- if (hit && member(hit, CCheckBox))
- {
- gOptions[idx] = ((CCheckBox *)hit)->IsChecked();
- }
- else if (hit && member(hit, CRadioControl))
- {
- gOptions[idx] = ((CCheckBox *)hit)->GetID();
- }
- else if (hit && member(hit, CPopupPane))
- {
- CPopupMenu *aMenu = ((CPopupPane *)hit)->GetMenu();
- short selectedItem, mID;
- MenuHandle mHandle;
-
- gBartender->FindMenuItem( theCommand, &mID, &mHandle, &selectedItem);
-
- gOptions[idx] = !(aMenu->ItemIsChecked(selectedItem));
- }
- else gOptions[idx] = 0;
- theCommand += gOptions[idx];
- }
- else
- {
- inherited::DoCommand( theCommand);
- return;
- }
-
- Data = GetResource('TEXT', (short)theCommand);
- styleHandle = (StScrpHandle) GetResource( 'styl', (short)theCommand);
- itsData = Data;
- if (Data)
- {
- itsMainPane->SetTextHandle(Data);
- if (styleHandle) itsMainPane->SetStyleScrap( 0, MAXINT, styleHandle, TRUE);
- }
- else
- {
- Str255 wTitle;
- Str255 wNumber;
- CopyPString((StringPtr)"\pNo help for this option\rIf necessary, add as TEXT resource ", wTitle);
- NumToString((short)theCommand, wNumber);
- ConcatPStrings(wTitle, wNumber);
- itsMainPane->SetTextPtr((char *)&wTitle[1], *wTitle);
- }
- }
-